﻿using ProjBackEnd.Areas.BizProj.Models;
using ProjBackEnd.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace ProjBackEnd.Areas.Financial.Models
{
   public class ResultFn : BaseResultInfoPaging
    {
        /// <summary>
        /// 结算单信息
        /// </summary>
        public List<FnExtInfo> fnextlist { get; set; } = new List<FnExtInfo>();
    }
    public class ReqFnSens : BaseUserRequest
    {
        /// <summary>
        /// 结算单敏感信息
        /// </summary>
        public FnCore fncore { get; set; }
    }
    public class ReqFnBase : BaseUserRequest
    {
        /// <summary>
        /// 结算单基础信息
        /// </summary>
        public FnBaseInfo fnbaseinfo { get; set; }
    }

    /// <summary>
    /// i 结算单核心信息
    /// </summary>
    public class FnCore : BaseOperableEntity
    {
        /// <summary>
        /// 结算单编号
        /// </summary>
        [RequiredConditional("optlb","UD",ErrorMessage ="结算单编号是必需的")]
        public int fnid { get; set; }
        /// <summary>
        /// 账单编号
        /// </summary>
        [RequiredConditional("optlb", "ID", ErrorMessage = "账单编号是必需的")]
        public int billid { get; set; }
        /// <summary>
        /// 客户编号
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "客户编号是必需的")]
        public int cusid { get; set; }
        /// <summary>
        /// 收付费标志：R-收费；P-付费
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "收付费标志是必需的")]
        public string rplb { get; set; }
        /// <summary>
        /// 结算金额
        /// </summary>
        public decimal amt_settle { get; set; }
        /// <summary>
        /// 税率
        /// </summary>
        public decimal taxrate { get; set; }
        /// <summary>
        /// 结算单进程：0-建档；1-已做费用；2-审批中；3-结算中；9-核销完成
        /// </summary>
        public string pid { get; set; }
        /// <summary>
        /// 结算单类别：BIZ-业务类；ADM-日常报销
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "结算单类别是必需的")]
        public string fntp { get; set; }
        /// <summary>
        /// 公司代码
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "公司代码是必需的")]
        public string comcd { get; set; }
        /// <summary>
        /// 审批方案编号
        /// </summary>
        public int revcaseid { get; set; }
        /// <summary>
        /// 打印标志
        /// </summary>
        public string printlb { get; set; } = "N";
    }

    /// <summary>
    /// ii 结算单基础信息
    /// </summary>
    public class FnBaseInfo : FnCore
    {
        /// <summary>
        /// 发票类别：0-普票；1-专票
        /// </summary>
        public string invotp { get; set; }
        /// <summary>
        /// 结算方式：0-现金；1-网银；2-支票
        /// </summary>
        public string settletp { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string remark { get; set; }
    }

    /// <summary>
    /// iii 结算单扩展信息
    /// </summary>
    public class FnExtInfo : FnBaseInfo
    {
        /// <summary>
        /// 收付费类别名称
        /// </summary>
        public string rplbnm { get; set; }
        /// <summary>
        /// 建档人
        /// </summary>
        public string creator { get; set; }
        /// <summary>
        /// 建档时间
        /// </summary>
        public string createdt { get; set; }
        /// <summary>
        /// 发票类别名称
        /// </summary>
        public string invotpnm { get; set; }
        /// <summary>
        /// 结算单进程名称
        /// </summary>
        public string pidnm { get; set; }
        /// <summary>
        /// 结算方式名称
        /// </summary>
        public string settletpnm { get; set; }
        /// <summary>
        /// 结算客户名称
        /// </summary>
        public string cusnm { get; set; }
        /// <summary>
        /// 审批方案名称
        /// </summary>
        public string revcasenm { get; set; }
        /// <summary>
        /// 结算人姓名
        /// </summary>
        public string settlenm { get; set; }
        /// <summary>
        /// 结算完成时间
        /// </summary>
        public string settledt { get; set; }
        /// <summary>
        /// 账单合计金额
        /// </summary>
        public decimal amt_total { get; set; }
        /// <summary>
        /// 账单预结金额
        /// </summary>
        public decimal amt_pre { get; set; }
        /// <summary>
        /// 账单已结金额
        /// </summary>
        public decimal amt_settled_bill { get; set; }
        /// <summary>
        /// 结算单已结金额
        /// </summary>
        public decimal amt_settled_fn { get; set; }
        /// <summary>
        /// 审批序号
        /// </summary>
        public int approvalsort { get; set; }
        /// <summary>
        /// 结算单类别名称：BIZ-业务类；ADM-行政类
        /// </summary>
        public string fntpnm { get; set; }
        /// <summary>
        /// 账单类别名称（对应CD_BASIC.ATTRCD = 'GSKM'）
        /// </summary>
        public string billtpnm { get; set; }
        /// <summary>
        /// 提交审批的时间
        /// </summary>
        public string submitdt { get; set; } = "";
        /// <summary>
        /// 已挂发票金额
        /// </summary>
        public decimal amt_invo_total { get; set; }
    }



    public class ResultLedger : BaseResultInfo
    {
        /// <summary>
        /// 实收实付信息
        /// </summary>
        public List<LedgerExtInfo> ledgerextlist { get; set; } = new List<LedgerExtInfo>();
    }
    public class ReqLedger : BaseUserRequest
    {
        public LedgerInfo ledgerinfo { get; set; }
    }

    /// <summary>
    /// i 实收实付核心信息
    /// </summary>
    public class LedgerInfo : BaseOperableEntity
    {
        /// <summary>
        /// 实收实付明细编号
        /// </summary>
        [RequiredConditional("optlb","UD",ErrorMessage = "实收实付明细编号是必需的")]
        public int fndtlid { get; set; }
        /// <summary>
        /// 结算单编号
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "结算单编号是必需的")]
        public int fnid { get; set; }
        /// <summary>
        /// 已实收实付金额
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "结算金额是必需的")]
        public decimal amt_settled { get; set; }
        /// <summary>
        /// 结算时间
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "结算时间是必需的")]
        public string settledt { get; set; }
        /// <summary>
        /// 付款结算账号
        /// </summary>
        public string acc_pay { get; set; }
        /// <summary>
        /// 收款结算账号
        /// </summary>
        public string acc_rec { get; set; }
    }

    /// <summary>
    /// ii 实收实付扩展信息
    /// </summary>
    public class LedgerExtInfo : LedgerInfo
    {
        /// <summary>
        /// 建档人姓名
        /// </summary>
        public string creator { get; set; }
        /// <summary>
        /// 建档时间
        /// </summary>
        public string createdt { get; set; }
    }


    public class ResultInvoice : BaseResultInfoPaging
    {
        /// <summary>
        /// 发票信息
        /// </summary>
        public List<InvoiceBaseInfo> involist { get; set; } = new List<InvoiceBaseInfo>();
    }

    public class ReqInvoice : BaseUserRequest
    {
        /// <summary>
        /// 发票信息
        /// </summary>
        [Required(ErrorMessage ="发票信息是必需的")]
        public InvoiceBaseInfo invoinfo { get; set; }
    }

    /// <summary>
    /// 发票结算单关联请求
    /// </summary>
    public class ReqFninvoRelation : BaseUserRequest
    {
        /// <summary>
        /// 结算单id
        /// </summary>
        public int fnid { get; set; }
        /// <summary>
        /// 发票id
        /// </summary>
        public int invoid { get; set; }
        /// <summary>
        /// 操作标识符
        /// </summary>
        [Required(ErrorMessage ="操作标识符是必需的")]
        public string optlb { get; set; }
        /// <summary>
        /// 结算发票列表
        /// </summary>
        public List<InvoiceSettleInfo> invofnlist { get; set; } = new List<InvoiceSettleInfo>();
    }

    /// <summary>
    /// 发票核心信息
    /// </summary>
    public class InvoiceBaseInfo : BaseOperableEntity
    {
        /// <summary>
        /// 发票id
        /// </summary>
        [RequiredConditional("optlb","UD",ErrorMessage ="发票id是必需的")]
        public int invoid { get; set; }
        /// <summary>
        /// 公司代码
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "公司代码是必需的")]
        public string comcd { get; set; }
        /// <summary>
        /// 发票代码
        /// </summary>
        public string invoicecode { get; set; } = "";
        /// <summary>
        /// 发票号
        /// </summary>
        public string invono { get; set; } = "";
        /// <summary>
        /// 校验码
        /// </summary>
        public string checkcode { get; set; } = "";
        /// <summary>
        /// 税控码
        /// </summary>
        public string fiscalcode { get; set; } = "";
        /// <summary>
        /// 发票类型（对应CD_BASIC.ATTRCD = 'FPLX'）
        /// </summary>
        public string invotp { get; set; } = "";
        /// <summary>
        /// 开票时间
        /// </summary>
        public string gendt { get; set; } = "";
        /// <summary>
        /// 销方全称
        /// </summary>
        public string seller { get; set; } = "";
        /// <summary>
        /// 销方税号
        /// </summary>
        public string sellertaxcode { get; set; } = "";
        /// <summary>
        /// 销方地址
        /// </summary>
        public string selleraddress { get; set; } = "";
        /// <summary>
        /// 销方电话
        /// </summary>
        public string sellertel { get; set; } = "";
        /// <summary>
        /// 销方开户行
        /// </summary>
        public string sellerbanknm { get; set; } = "";
        /// <summary>
        /// 销方银行账号
        /// </summary>
        public string sellerbankno { get; set; } = "";
        /// <summary>
        /// 购方全称
        /// </summary>
        public string buyer { get; set; } = "";
        /// <summary>
        /// 购方税号
        /// </summary>
        public string buyertaxcode { get; set; } = "";
        /// <summary>
        /// 购方地址
        /// </summary>
        public string buyeraddress { get; set; } = "";
        /// <summary>
        /// 购方电话
        /// </summary>
        public string buyertel { get; set; } = "";
        /// <summary>
        /// 购方开户行
        /// </summary>
        public string buyerbanknm { get; set; } = "";
        /// <summary>
        /// 购方银行账号
        /// </summary>
        public string buyerbankno { get; set; } = "";
        /// <summary>
        /// 票面开票人
        /// </summary>
        public string drawer { get; set; } = "";
        /// <summary>
        /// 票面收款人
        /// </summary>
        public string payee { get; set; } = "";
        /// <summary>
        /// 票面复核人
        /// </summary>
        public string reviewer { get; set; } = "";
        /// <summary>
        /// 票面合计金额
        /// </summary>
        public decimal amt_total { get; set; }
        /// <summary>
        /// 不含税金额
        /// </summary>
        public decimal amt_notax { get; set; }
        /// <summary>
        /// 税额
        /// </summary>
        public decimal amt_tax { get; set; }
        /// <summary>
        /// 已挂结算单的金额
        /// </summary>
        public decimal amt_fn { get; set; }
        /// <summary>
        /// 关联发票编号。如该记录发票类型为【冲红】，此字段则表示被冲红发票号
        /// </summary>
        public string relatedcode { get; set; } = "";
        /// <summary>
        /// 红冲原因
        /// </summary>
        public string validreason { get; set; } = "";
        /// <summary>
        /// 红冲时间
        /// </summary>
        public string validdt { get; set; } = "";
        /// <summary>
        /// 发票备注
        /// </summary>
        public string remark { get; set; } = "";
        /// <summary>
        /// 访问码（备用，自助开票用）
        /// </summary>
        public string accesscode { get; set; } = "";
        /// <summary>
        /// 发票状态：0-未开具；1-正常；3-红冲；4-被红冲；E-开具失败；9-作废
        /// </summary>
        public string pid { get; set; } = "";
        /// <summary>
        /// 发票类别：B-我方为购方；S-我方为销方
        /// </summary>
        public string invocatelog { get; set; } = "";
        /// <summary>
        /// 税率
        /// </summary>
        public decimal taxrate { get; set; }
        /// <summary>
        /// 发票类型名称
        /// </summary>
        public string invotpnm { get; set; }
        /// <summary>
        /// 购方客户id
        /// </summary>
        public int cusid_buyer { get; set; }
        /// <summary>
        /// 销方客户id
        /// </summary>
        public int cusid_seller { get; set; }
    }

    /// <summary>
    /// 发票结算单关联信息应答
    /// </summary>
    public class ResultInvoFN : BaseResultInfo
    {
        /// <summary>
        /// 发票结算单关联信息列表
        /// </summary>
        public List<InvoiceFN> invofnlist { get; set; } = new List<InvoiceFN>();
    }

    /// <summary>
    /// 发票结算单关联信息
    /// </summary>
    public class InvoiceFN : InvoiceBaseInfo
    {
        /// <summary>
        /// 结算单id
        /// </summary>
        public int fnid { get; set; }
    }

    /// <summary>
    /// 结算发票信息
    /// </summary>
    public class InvoiceSettleInfo
    {
        /// <summary>
        /// 结算单id
        /// </summary>
        public int fnid { get; set; }
        /// <summary>
        /// 发票id
        /// </summary>
        public int invoid { get; set; }
        /// <summary>
        /// 发票结算金额
        /// </summary>
        public decimal amt_invo { get; set; }
    }


    public class ResultFNInvo : BaseResultInfo
    {
        /// <summary>
        /// 结算单发票关联信息列表
        /// </summary>
        public List<FNInvo> fninvolist { get; set; } = new List<FNInvo>();
    }
    /// <summary>
    /// 结算单发票关联信息
    /// </summary>
    public class FNInvo
    {
        /// <summary>
        /// 结算单id
        /// </summary>
        public int fnid { get; set; }
        /// <summary>
        /// 发票id
        /// </summary>
        public int invoid { get; set; }
        /// <summary>
        /// 结算单总金额
        /// </summary>
        public decimal amt_settle { get; set; }
        /// <summary>
        /// 结算单税率
        /// </summary>
        public decimal taxrate { get; set; }
        /// <summary>
        /// 结算单类型
        /// </summary>
        public string fntp { get; set; } = "";
        /// <summary>
        /// 结算单状态
        /// </summary>
        public string pid { get; set; } = "";
        /// <summary>
        /// 结算单状态名称
        /// </summary>
        public string pidnm { get; set; } = "";
        /// <summary>
        /// 结算客户id
        /// </summary>
        public int cusid { get; set; }
        /// <summary>
        /// 结算客户名称
        /// </summary>
        public string cusnm { get; set; } = "";
        /// <summary>
        /// 建档时间
        /// </summary>
        public string createdt { get; set; } = "";
        /// <summary>
        /// 建档人id
        /// </summary>
        public string createid { get; set; } = "";
        /// <summary>
        /// 建档人姓名
        /// </summary>
        public string creator { get; set; } = "";
        /// <summary>
        /// 已开票金额
        /// </summary>
        public decimal amt_invosum { get; set; }
        /// <summary>
        /// 未开票金额
        /// </summary>
        public decimal amt_involeft { get; set; }
        /// <summary>
        /// 打印标志
        /// </summary>
        public string printlb { get; set; }
    }

}